package com.example.myapplication;

import android.Manifest;
import android.os.Build;
import android.os.Bundle;
import android.view.View;

import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContract;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.RequiresApi;

import com.blankj.utilcode.util.LogUtils;
import com.everyline.baselibrary.activity.BasePresenterActivity;
import com.example.myapplication.databinding.ActivityMainBinding;
import com.google.gson.Gson;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class MainActivity extends BasePresenterActivity<ActivityMainBinding, TestPresenter> implements TestContract.View {


    private List<String> mCurrentSelectedPath = new ArrayList<>();//图片集合
    private String[] per = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE};
    private ActivityResultLauncher launcher;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        launcher = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() {
            @Override
            public void onActivityResult(Map<String, Boolean> result) {
                LogUtils.d(result);
                result.entrySet().forEach(new Consumer<Map.Entry<String, Boolean>>() {
                    @Override
                    public void accept(Map.Entry<String, Boolean> stringBooleanEntry) {

                        stringBooleanEntry.getKey();
                        stringBooleanEntry.getKey().equals(Manifest.permission.WRITE_EXTERNAL_STORAGE);
                        stringBooleanEntry.getValue();
                    }
                });

            }
        });
        mPresenter = new TestPresenter();
        mCurrentSelectedPath.add("/storage/emulated/0/Android/data/com.phone.tankeout/files/Pictures/IMG_CMP_101230745.jpeg");

    }

    @Override
    protected void initData() {


    }


    @Override
    protected void initListener() {
        mViewDataBinding.tvOk2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Map<String, String> map = new HashMap<>();
                map.put("loginname", "18513102256");
                map.put("password", "123456");

                mPresenter.applogin2(map);
            }
        });
        mViewDataBinding.tvOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Map<String, String> map = new HashMap<>();
                map.put("loginname", "18513102256");
                map.put("password", "123456");

                mPresenter.applogin(map);

//                Map<String, RequestBody> map = new HashMap<>();
//                map.put("orderid", RequestBody.create(1 + "", MediaType.get("application/json; charset=utf-8")));
//                map.put("text", RequestBody.create("测试室测试测试", MediaType.get("application/json; charset=utf-8")));
//                for (String s : mCurrentSelectedPath) {
//                    File file = new File(s);
//                    map.put("image\"; filename=\"" + file.getName(), RequestBody.create(file, MediaType.get("text/x-markdown; charset=utf-8")));
//                }
//                mPresenter.tousupaotuiorder(map);

//                launcher.launch(per);
            }
        });

    }

    @Override
    public void showapplogin(String s) {


        LogUtils.d("sssssssssssss===========", s);

    }

    @Override
    public void showapplogin2(LoginBean loginBean) {
        LogUtils.d("loginBean=============", loginBean.getToken());
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void dismissLoading() {

    }

    @Override
    public void showError(Throwable throwable) {

    }
}